<cfcomponent output="false">
	
	<!---  --->
	
	<cffunction name="select" access="public" output="false" returntype="string">
		<cfargument name="name" required="true" />
		<cfargument name="label" required="false" default="" />
		<cfargument name="query" required="true" type="query" />
		<cfargument name="value" required="false" default="" />
		<cfargument name="blank" required="false" default="false" />
		<cfargument name="option" required="false" default=" - " />
		<cfargument name="required" required="false" default="false" />
		<cfargument name="onchange" required="false" default="" />
		<cfargument name="style" required="false" default="" />
		<cfargument name="optionText" required="false" default="name" />
		<cfargument name="validate" required="false" default="" />
		
		<cfset var local = {} />
		
		<cfif arguments.label eq "">
			<cfset arguments.label = arguments.name />
		</cfif>
		
		<!--- set required --->
		<cfset local.required = "" />
		<cfif arguments.required>
			<cfset local.required = "validate='required'" />
		</cfif>
		
		<!--- set onchange --->
		<cfset local.onchange = "" />
		<cfif arguments.onchange neq "">
			<cfset local.onchange = 'onchange="#arguments.onchange#"' />
		</cfif>
		
		<!--- set style --->
		<cfset local.style = "" />
		<cfif arguments.style neq "">
			<cfset local.style = 'style="#arguments.style#"' />
		</cfif>
		
		<cfsavecontent variable="local.result">
			<cfoutput>
				<select 
					name="#arguments.name#" 
					title="#arguments.label#" 
					#local.required# #local.onchange# 
					#local.style#
					<cfif arguments.validate neq "">
						validate="#arguments.validate#"
					</cfif>
				>
					<cfif arguments.blank>
						<option value="">#arguments.option#</option>
					</cfif>
					<cfloop query="arguments.query">
						<option value="#arguments.query.id#" <cfif arguments.value eq arguments.query.id>selected</cfif>>#evaluate("arguments.query.#arguments.optionText#")#</option>
					</cfloop>
				</select>
			</cfoutput>
		</cfsavecontent>

		<cfreturn local.result />
		
	</cffunction>
	
	<!--- --->
	
	<cffunction name="img" access="public" output="false" returntype="string">
		<cfargument name="path" required="true" />
		<cfargument name="id" required="false" default="" />
		<cfargument name="style" required="false" default="" />
		<cfargument name="class" required="false" default="" />
		<cfargument name="bubble" required="false" default="" />
		<cfargument name="onclick" required="false" default="" />
		<cfargument name="onload" required="false" default="" />
		<cfargument name="aws" required="false" default="false" />
		<cfargument name="refresh" required="false" default="false" />
		
		<cfset var local = {} />
		
		<cfsavecontent variable="local.result">
			<cfoutput>
				<cfset local.path = "/assets/media/" />
				<cfif arguments.aws>
					<cfset local.path = "https://s3.amazonaws.com/FundrImages/" />
				</cfif>
				
				<img src="#local.path##arguments.path#<cfif arguments.refresh>?#timeformat(now(),"hhmmss")#</cfif>" 

				<cfif arguments.class neq "">
					class="#arguments.class#"
				</cfif> 
				<cfif arguments.id neq "">
					id="#arguments.id#"
				</cfif> 
				<cfif arguments.style neq ''>
					style="#arguments.style#"
				</cfif> 
				<cfif arguments.onclick neq "">
					onclick="javascript:#arguments.onclick#"
				</cfif>
				<cfif arguments.bubble neq "">
					bubble="#arguments.bubble#"
				</cfif>
				<cfif arguments.onload neq "">
					onload="javascript:#arguments.onload#"
				</cfif>
				/>
			</cfoutput>
		</cfsavecontent>

		<cfreturn local.result />
		
	</cffunction>
	
	<!--- --->
	
	<cffunction name="checkboxes" access="public" output="true" returntype="string">
		<cfargument name="name" required="true" />
		<cfargument name="value" required="false" default="1" />
		<cfargument name="labels" required="false" default="#['Yes','No']#" />
		<cfargument name="values" required="false" default="#[1,0]#" />
		<cfargument name="bubbles" required="false" default="#['','']#" />
		<cfargument name="onchange" required="false" default="" />
		<cfargument name="query" required="false" />

		<cfset var local = {} />
		
		<!--- accept query object --->
		<cfif structKeyExists(arguments,"query")>
			<cfset arguments.labels = [] />
			<cfset arguments.values = [] />
			<cfset arguments.bubbles = [] />
			<cfloop query="arguments.query">
				<cfset arrayAppend(arguments.labels,arguments.query.name) />
				<cfset arrayAppend(arguments.values,arguments.query.id) />
				<cfif listFindNoCase(arguments.query.columnList,'description')>
					<cfset arrayAppend(arguments.bubbles,query.description) />
				</cfif>
			</cfloop>
		</cfif>
		
		<cfsavecontent variable="local.result">
			<cfoutput>
				<ul class="checkboxes" id="checkboxes_#arguments.name#">
					<cfset local.iterator = 0 />
					<cfloop array="#arguments.values#" index="local.i">
						<cfset local.iterator++ />
						<cfset local.label = arguments.labels[local.iterator] />
						<li 
							value="#local.i#"
							class="checkbox <cfif local.i eq arguments.value> selected</cfif>"
							onclick="javascript:Checkbox.toggle(this);"
							<cfif local.iterator lte arrayLen(arguments.bubbles) and arguments.bubbles[local.iterator] neq "">
								bubble="#arguments.bubbles[local.iterator]#"
							</cfif>
						>
							
							#local.label#
							
							<input 
								type="checkbox" 
								title="#local.label#" 
								name="#arguments.name#" 
								id="#arguments.name#_#local.iterator#" 
								value="#local.i#" 
								style="display:none;" 
								<cfif arguments.onchange neq ''>onchange="javascript:#arguments.onchange#"</cfif>
								<cfif local.i eq arguments.value> checked</cfif>
							/>
						</li>
					</cfloop>
				</ul>
			</cfoutput>
		</cfsavecontent>
		
		<cfreturn local.result />

	</cffunction>
	
	<!--- --->
	
	<cffunction name="star" access="public" output="true" returntype="string">

		<cfset var local = {} />
		
		<cfsavecontent variable="local.result">
			<cfoutput>
				<span class="required_asterisk" title="Required">*</span>
			</cfoutput>
		</cfsavecontent>
		
		<cfreturn local.result />

	</cffunction>
	
	<!--- --->
	
	<cffunction name="radio" access="public" output="true" returntype="string">
		<cfargument name="name" required="true" />
		<cfargument name="value" required="false" default="1" />
		<cfargument name="labels" required="false" default="#['Yes','No']#" />
		<cfargument name="values" required="false" default="#[1,0]#" />
		<cfargument name="bubbles" required="false" default="#['','']#" />
		<cfargument name="onchange" required="false" default="" />
		<cfargument name="vertical" required="false" default="false" />
		<cfargument name="width" required="false" default="" />
		<cfargument name="query" required="false" />
		<cfargument name="class" required="false" default="" />

		<cfset var local = {} />
		
		<!--- accept query object --->
		<cfif structKeyExists(arguments,"query")>
			<cfset arguments.labels = [] />
			<cfset arguments.values = [] />
			<cfset arguments.bubbles = [] />
			<cfloop query="arguments.query">
				<cfset arrayAppend(arguments.labels,arguments.query.name) />
				<cfset arrayAppend(arguments.values,arguments.query.id) />
				<cfif listFindNoCase(arguments.query.columnList,'description')>
					<cfset arrayAppend(arguments.bubbles,query.description) />
				</cfif>
			</cfloop>
		</cfif>
		
		<cfsavecontent variable="local.result">
			<cfoutput>
				<ul class="radio<cfif arguments.class neq ''> #arguments.class#</cfif>" id="radio_#arguments.name#">
					<cfset local.iterator = 0 />
					<cfloop array="#arguments.values#" index="local.i">
						<cfset local.iterator++ />
						<cfset local.label = arguments.labels[local.iterator] />
						<li 
							value="#local.i#"
							class="radio-option	<cfif arguments.vertical> vertical</cfif><cfif local.i eq arguments.value> selected</cfif><cfif local.iterator eq 1> first</cfif><cfif local.iterator eq arrayLen(arguments.values)> last</cfif>"
							onclick="javascript:Radio.set('#arguments.name#','#local.i#');"
							<cfif arguments.width neq ''>style="width:#arguments.width#;"</cfif>
							<cfif local.iterator lte arrayLen(arguments.bubbles) and arguments.bubbles[local.iterator] neq "">
								bubble="#arguments.bubbles[local.iterator]#"
							</cfif>
						>
							
							#local.label#
							
							<input 
								type="radio" 
								title="#local.label#" 
								name="#arguments.name#" 
								id="#arguments.name#_#local.iterator#" 
								value="#local.i#" 
								style="display:none;" 
								<cfif arguments.onchange neq ''>onchange="javascript:#arguments.onchange#"</cfif>
								<cfif local.i eq arguments.value> checked</cfif>
							/>
						</li>
					</cfloop>
				</ul>
			</cfoutput>
		</cfsavecontent>
		
		<cfreturn local.result />

	</cffunction>
	
	<!--- --->
	
	<cffunction name="bubble" access="public" output="true" returntype="string">
		<cfargument name="message" required="true" />

		<cfset var local = {} />
		
		<cfsavecontent variable="local.result">
			<cfoutput>
				<div class="chat-bubble" style="display:none;">
					<span id="bubble-text">#arguments.message#</span>
					<div class="chat-bubble-arrow-border"></div>
					<div class="chat-bubble-arrow"></div>
				</div>
			</cfoutput>
		</cfsavecontent>
		
		<cfreturn clean(local.result) />

	</cffunction>
	
	<!--- --->
	
	<cffunction name="clean" access="public" output="true" returntype="string">
		<cfargument name="string" required="true" />

		<cfset arguments.string = rereplace(arguments.string,'\t','','ALL') />		
		<cfset arguments.string = rereplace(arguments.string,'\n','','ALL') />			
		<cfset arguments.string = rereplace(arguments.string,'\r','','ALL') />		
				
		<cfreturn trim(arguments.string) />

	</cffunction>
	
	<!--- --->
	
	<cffunction name="triRadio" access="public" output="true" returntype="string">
		<cfargument name="name" required="true" />
		<cfargument name="value" required="false" default="" />
		<cfargument name="label" required="false" default="" />
		<cfargument name="values" required="false" default="#['',1,0]#" />
		<cfargument name="bubbles" required="false" default="#['','']#" />
		<cfargument name="onchange" required="false" default="" />
		<cfargument name="class" required="false" default="" />

		<cfset var local = {} />
		
		<cfset arguments.labels = "#[arguments.label,arguments.label,'Not #arguments.label#']#" />
		
		<cfsavecontent variable="local.result">
			<cfoutput>
				<ul class="triRadio" id="triRadio_#arguments.name#">
					<cfset local.iterator = 0 />
					<cfloop array="#arguments.values#" index="local.i">
						<cfset local.iterator++ />
						<cfset local.label = arguments.labels[local.iterator] />
						<li 
							value="#local.i#"
							count="#local.iterator#"
							class="checkbox <cfif local.i neq ''> checked</cfif><cfif local.i neq arguments.value> hidden</cfif><cfif arguments.class neq ''> #arguments.class#</cfif>"
							onclick="javascript:TriRadio.toggle(this);"
							<cfif local.iterator lte arrayLen(arguments.bubbles) and arguments.bubbles[local.iterator] neq "">
								bubble="#arguments.bubbles[local.iterator]#"
							</cfif>
							<cfif local.i eq 0>
								style="background-color:rgb(231,122,101);"
							</cfif>
						>
							
							#local.label#
							
							<input 
								type="radio" 
								title="#local.label#" 
								name="#arguments.name#" 
								id="#arguments.name#_#local.iterator#" 
								value="#local.i#" 
								style="display:none;" 
								<cfif arguments.onchange neq ''>onchange="javascript:#arguments.onchange#"</cfif>
								<cfif local.i eq arguments.value> checked</cfif>
							/>
						</li>
					</cfloop>
				</ul>
			</cfoutput>
		</cfsavecontent>
		
		<cfreturn local.result />

	</cffunction>
	
	<!--- --->
	
	<cffunction name="form" access="public" output="true" returntype="string">
		<cfargument name="name" required="true" />
		<cfargument name="class" required="false" default="" />
		<cfargument name="method" required="true" hint="thisService.thisMethod" />
		<cfargument name="onsubmit" required="false" default="" hint="return validation" />
		<cfargument name="style" required="false" default="" />
		
		<cfset var local = {} />
		
		<cfset local.methodArray = listToArray(arguments.method,'.') />
		<cfset arguments.cfc = local.methodArray[1] />
		<cfset arguments.method = local.methodArray[2] />
				
		<cfsavecontent variable="local.result">
			<cfoutput>
				<form 
					class="#arguments.class#" 
					method="POST" 
					name="#arguments.name#" 
					id="#arguments.name#" 
					action="#$.link.form(cfc=arguments.cfc,method=arguments.method)#" 
					onsubmit="#arguments.onsubmit#"
					<cfif arguments.style neq "">
						style="#arguments.style#"
					</cfif>
				>
			</cfoutput>
		</cfsavecontent>
		
		<cfreturn local.result />

	</cffunction>
	
	<!--- --->

</cfcomponent>